﻿
namespace SistemaLogistica.Business.Logic
{
    using System;
    using System.Collections.Generic;
    using SistemaLogistica.Business.Entities;
    using SistemaLogistica.Business.Entities.Generics;
    using SistemaLogistica.DataAccess;

    public class ClienteManager
    {
        private ClienteManager() { }

        private static readonly ClienteManager instancia = new ClienteManager();

        public static ClienteManager Instancia
        {
            get { return instancia; }
        }

        public List<Cliente> Listar()
        {
            try
            {
                List<Cliente> clientes = new List<Cliente>();

                List<Natural> naturales = ListarNaturales();
                foreach (Natural natural in naturales)
                {
                    clientes.Add(natural);
                }

                List<Juridico> juridicos = ListarJuridicos();
                foreach (Juridico juridico in juridicos)
                {
                    clientes.Add(juridico);
                }

                clientes.Sort(new GenericComparer<Cliente>("IdCliente", GenericComparer<Cliente>.SortOrder.Ascending)); 
                return clientes;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<Natural> ListarNaturales()
        {
            try
            {
                return ClienteData.Instancia.ListarNaturales();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<Natural> BuscarNatural(string dni)
        {
            try
            {
                return ClienteData.Instancia.BuscarNatural(dni);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<Juridico> ListarJuridicos()
        {
            try
            {
                return ClienteData.Instancia.ListarJuridicos();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<Juridico> BuscarJuridico(string ruc)
        {
            try
            {
                return ClienteData.Instancia.BuscarJuridico(ruc);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool AgregarNatural(Natural natural)
        {
            try
            {
                return ClienteData.Instancia.AgregarNatural(natural);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool AgregarJuridico(Juridico juridico)
        {
            try
            {
                return ClienteData.Instancia.AgregarJuridico(juridico);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void EditarNatural(Natural natural)
        {
            try
            {
                ClienteData.Instancia.EditarNatural(natural);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void EditarJuridico(Juridico juridico)
        {
            try
            {
                ClienteData.Instancia.EditarJuridico(juridico);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void Eliminar(int idCliente)
        {
            try
            {
                ClienteData.Instancia.Eliminar(idCliente);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
